package org.niu.tree;

public class SumNumbers {
    int ans = 0;
    public int sumNumbers (TreeNode root) {
        // write code here
        helper(root,0);
        return ans;
    }
    public void helper (TreeNode root,int sum) {
        // write code here
        if(root == null){
            return;
        }
        if(root.left == null && root.right == null){
            ans += 10*sum+root.val;
        }
        helper(root.left,10*sum+root.val);
        helper(root.right,10*sum+root.val);
    }
}
